//app.js
App({
  onLaunch: function () {
    //调用API从本地缓存中获取数据
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs);
    this.getopenid();
  },

  getUserInfo: function (cb) {
    var that = this
    if (this.globalData.userInfo) {
      typeof cb == "function" && cb(this.globalData.userInfo)
    } else {
      //调用登录接口
      wx.getUserInfo({
        withCredentials: false,
        success: function (res) {
          that.globalData.userInfo = res.userInfo
          typeof cb == "function" && cb(that.globalData.userInfo)
        }
      })
    }
  },
  getopenid: function () {
    var that = this;
    /* 获取登录信息开始 */
    //调用登录接口
    wx.login({
      success: function (loginCode) {
        var appidinfo = that.globalData.APPID;
        var secretinfo = that.globalData.APPSTART;
        /*
        console.log("service=" + service);
        console.log("appid=" + that.Config.APPID);
        console.log("jsCode=" + loginCode.code);
        */

        //调用request请求api转换登录凭证  
        wx.request({
          url: 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appidinfo + '&secret=' + secretinfo + '&grant_type=authorization_code&js_code=' + loginCode.code,
          header: {
            'content-type': 'application/json'
          },
          success: function (res) {
            that.globalData.openid = res.data.openid;//设置openid
            console.log(666);
            console.log(that.globalData.openid)
            //that.getInviteCode();
          },
          fail: function (res) {
            console.log("fail:" + res);
          },
        })

      }
    })
    /* 获取登录信息结束 */
  },
  globalData: {
    userInfo: null,
    APPID: 'wxdb65d5b1a789f99c',
    APPSTART: '7aa1070ee38f898e83058407da1400a4',
    openid: null,

  }
})
